﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using System.Linq;
using System.Text;
using LinFu.IoC.Configuration;
using LinFu.IoC.Interfaces;
using LinFu.IoC;
namespace CoreEx.Database.Client.Implementation
{
    [Factory(typeof(DbDataAdapter))]
    [Factory(typeof(IDbDataAdapter))]
    public class DbDataAdapterFactory : IFactory
    {
        public object CreateInstance(IFactoryRequest request)
        {
            var connectionInfo = request.Container.GetService<DbConnectionInfo>(request.ServiceName);

            //Create a provider factory
            var providerFactory = DbProviderFactories.GetFactory(connectionInfo.ProviderName);

            var dbDataAdapter = providerFactory.CreateDataAdapter();

            return dbDataAdapter;
        }
    }
}
